using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;

namespace CodePlex.Resourceful.Examples
{
    public static class StikkitExample
    {

        public static void Run()
        {


            // get api key
            string apiKey = Environment.GetEnvironmentVariable("STIKKIT");


        
            // client
            Client client = new Client(new Uri("http://api.stikkit.com/"));
            client.Tracer.AddListener(Console.Out);
            client.Throttle = TimeSpan.FromSeconds(1.5);


            NameValuePairs parameters = new NameValuePairs();
            parameters["api_key"] = apiKey;


            // add a new stikkit
            parameters["raw_text"] = "auto stikkit on " + Utils.ToHttpDate(DateTime.Now);

            string newStikkitURI = client.PostRepresentation("stikkits", MediaType.ApplicationExWwwFormUrlencoded, parameters).Headers[HttpHeader.Location];

           


            parameters.Clear();
            parameters["api_key"] = apiKey;


            // get feed (should include new stikkit)
            client.GetRepresentation("stikkits",MediaType.ApplicationJson + ", */*",parameters);    // TODO should be a better way to do charset


            Utils.Prompt();



            // update the stikkit

             // add a new stikkit
            parameters["raw_text"] = "auto stikkit2 on " + Utils.ToHttpDate(DateTime.Now);

            client.PutRepresentation("stikkits", MediaType.ApplicationExWwwFormUrlencoded, parameters);


            parameters.Clear();
            parameters["api_key"] = apiKey;


            // delete the new stikkit

          

            // http://community.valuesofn.com/stikkit/index.php/topic,723.0.html
           

            parameters["_method"] = "delete";
            client.PostRepresentation(newStikkitURI, MediaType.ApplicationExWwwFormUrlencoded, parameters);



            parameters.Clear();
            parameters["api_key"] = apiKey;


            // get feed (should not include new stikkit)
            client.GetRepresentation("stikkits", MediaType.ApplicationAtomXml + ", */*", parameters);

            Utils.Prompt();


        }





    }
}
